/**
 * 
 */
package hihocoder;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 影院座位 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int N=scanner.nextInt();
		int M=scanner.nextInt();
		boolean[] occped=new boolean[N];
		int idleCount=0;
		for (int i = 0; i < N; i++) {
			if(scanner.nextInt()==1){
				occped[i]=true;
			}
			else {
				idleCount++;
			}
		}
		if(idleCount<M){
			System.out.println(-1);
			return;
		}
		ArrayList<Integer> idleIndexes=new ArrayList<>(idleCount);
		int count=0;
		int start=-1;
		long totalMinSum=100000000001L;
		for (int i = 0; i < N; i++) {
			if(!occped[i]){
				idleIndexes.add(i);
				count++;
			}
			if(count==M){
				int end=start+M;
				start++;
				long minSum=100000000001L;//不同集结点的最小值
				for (int j = start; j <= end; j++) {//作为集结点
					long sum=0;
					for (int j2 = start; j2 <= end; j2++) {//计算所有空闲点到集结点的距离
						sum+=Math.abs(idleIndexes.get(j)-idleIndexes.get(j2));
					}
					minSum=Math.min(minSum, sum);
				}
				count--;
				totalMinSum=Math.min(minSum, totalMinSum);//不同范围的最小值
			}
		}
		System.out.println(totalMinSum);
	}

}
